<template>
  <div>
    <div class="index-module">
      <div class="flex-vertical">
        <h2>视频学习</h2>
        <!-- <div class="more">更多</div> -->
      </div>
      <div class="video-learn">
        <div class="item" v-for="item in dataList" :key="item.id">
          <img
            :src="item.coverImage"
            alt=""
            @click="openVideo(item.url)"
          />
          <div class="title">{{item.title}}</div>
          <div class="avatar flex-vertical">
            <div class="play">
              <span class="iconfont icon-24gf-playCircle"></span>
            </div>
            <img
              src="https://file.youlai.cn/cnkfile1/M02/7E/4A/2BDD8975E8AEE4193E63BB4A21517E4AWT.jpeg"
              alt=""
            />

            <span>{{item.author}}</span>
          </div>
          <div class="brief">呼吸与危重症医学科</div>
          <span class="iconfont icon-renzhengyonghu"></span>
        </div>
      </div>
      <Modal v-model="show" title="​抽烟的危害" @on-cancel="cancel">
        <video
          id="video"
          width="490"
          height="278"
          controls
          :src="videoUrl"
        ></video>
        <div slot="footer"></div>
      </Modal>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      dataList:[],
      videoUrl:""
    };
  },
  created(){
    this.getDataList()
  },
  methods: {
    getDataList(){
      this.HttpService.getAllVideo().then(res =>{
        console.log(res)
        let data = res.data.data;
        data.map(item => {
          if(item.status == '1') {
            this.dataList.push(item)
          }
        })
      })
    },
    openVideo(videoUrl) {
      this.videoUrl = videoUrl
      this.show = !this.show;
    },
    cancel(){
      let video = document.querySelector("#video");
      console.log(video);
      this.enterPictureInPicture(video)
    },
    // 启动画中画
    enterPictureInPicture(videoElement) {
      if (
        document.pictureInPictureEnabled &&
        !videoElement.disablePictureInPicture
      ) {
        try {
          if (document.pictureInPictureElement) {
            document.exitPictureInPicture();
          }
          videoElement.requestPictureInPicture();
        } catch (err) {
          console.error(err);
        }
      }
    },
  },
};
</script>

<style lang='less' scoped>
.video-learn {
  display: flex;
  flex-wrap: wrap;
  // justify-content: space-between;
  position: relative;
  .item {
    margin-right: 20px;
    margin-top: 15px;
    height: 250px;
    background-color: #fff;
    border-radius: 15px;
    position: relative;
    img {
      width: 280px;
      height: 163px;
      border-radius: 15px 15px 0px 0px;
    }
    .title {
      width: 90%;
      margin: 0 auto;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .avatar {
      margin-left: 15px;
      color: #858585;
      line-height: 30px;
      img {
        width: 20px;
        height: 20px;
        border-radius: 50%;
      }
      .play {
        position: absolute;
        left: 50%;
        top: 30%;
        transform: translateX(-50%);
        span {
          font-size: 35px;
          color: #fff;
        }
      }
    }
    .brief {
      font-size: 14px;
      margin-left: 15px;
      color: #858585;
    }
    .icon-renzhengyonghu {
      position: absolute;
      bottom: 10px;
      right: 10px;
      font-size: 21px;
      color: #fad74f;
    }
  }
}
</style>
